<div class="yui-g">
    <table id="editgrid"></table>
    <div id="pager"></div>
</div>
<script type="text/javascript">
    var lastsel3;
    jQuery(document).ready(function(){
        jQuery("#editgrid").jqGrid({
            url:'<?=base_url();?>index.php/admin/preguntas/post',
            datatype: 'json',
            mtype: 'POST',
            colNames:['id','id_usuario','id_vendedor','id_producto','tipo','diahora','texto','pendiente'],
            colModel :[
                {name:'id', index:'id', width:90,editable:false,editoptions:{size:10}, hidden:false},
                {name:'id_usuario', index:'id_usuario', width:90,editable:false,editoptions:{size:10}, hidden:true},
                {name:'id_vendedor', index:'id_vendedor', width:80,editable:false,editoptions:{size:10}, hidden:true, align:'right'},
                {name:'id_producto', index:'id_producto', width:80,editable:false,editoptions:{size:10}, align:'right', hidden:true},
                {name:'tipo', index:'tipo', width:80,editable:false,editoptions:{size:10}, align:'left'},
                {name:'diahora', index:'diahora', width:80,editable:true,editoptions:{size:10}, align:'left', sorttype: 'date', datefmt: 'M d, Y at h:i'},
                {name:'texto', index:'texto', width:80,editable:true,editoptions:{size:10}, align:'left'},
                {name:'pendiente',index:'pendiente', width:60, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"},align:'center'},
            ],

            pager: '#pager',
            rowNum:20,
            rowList:[10,20,30],
            sortname: 'id_pregunta',
            sortorder: 'desc',
            viewrecords: true,
            caption: 'Preguntas',
            height:'100%',
            width:900,
            onSelectRow: function(id){
                jQuery('#editgrid').jqGrid('restoreRow',lastsel3);
                jQuery('#editgrid').jqGrid('editRow',id,true);
                lastsel3=id;
            },
            editurl:"<?=base_url();?>index.php/admin/preguntas/guardar",
            subGrid: true, caption: "Categorias", subGridRowExpanded: function(subgrid_id, id_row) {
                var subgrid_table_id,
                pager_id;
                subgrid_table_id = subgrid_id+"_t";
                pager_id = "p_"+subgrid_table_id;
                $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
                jQuery("#"+subgrid_table_id).jqGrid({
                    //url:"subgrid.php?q=2&id="+row_id,
                    url:'<?=base_url();?>index.php/admin/preguntas/post1/'+id_row,
                    datatype: "json",
                    mtype: 'POST',
                    colNames:['id_respuesta','id_pregunta','id_usuario','id_vendedor','id_producto','diahora','texto'],
                    colModel :[
                        {name:'id_respuesta', index:'id_respuesta', width:90,editable:false,editoptions:{size:10}, hidden:true},
                        {name:'id_pregunta', index:'id_pregunta', width:90,editable:false,editoptions:{size:10}, hidden:true},
                        {name:'id_usuario', index:'id_usuario', width:90,editable:true,editoptions:{size:10}, hidden:true},
                        {name:'id_vendedor', index:'id_vendedor', width:90,editable:true,editoptions:{size:10}, hidden:true},
                        {name:'id_producto', index:'id_producto', width:90,editable:true,editoptions:{size:10}, hidden:true},
                        {name:'diahora', index:'diahora', width:90,editable:true,editoptions:{size:10}},
                        {name:'texto', index:'texto', width:90,editable:true,editoptions:{size:10}},
                    ],
                    rowNum:20,
                    pager: pager_id,
                    sortname: 'num',
                    sortorder: "asc",
                    height: '100%',
                    width: 1200,
                    editurl:"<?=base_url();?>index.php/admin/preguntas/guardar1/"+id_row
                });
                jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:true,add:true,del:true})
            }

        });
        jQuery("#editgrid").jqGrid('navGrid',"#pager",{edit:true,add:true,del:true});
    });
</script>
